package com.qf.staff.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.common.base.result.RespResult;
import com.qf.staff.common.qo.PayrollQo;
import com.qf.staff.common.vo.PayrollVo;
import com.qf.staff.service.PayrollService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "部门薪资管理Api")
@RestController
@RequestMapping("/payroll")
public class PayrollController {
    @Resource
    PayrollService payrollService;

    /*
     *
     * */
    @ApiOperation("查询所有薪资信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "页码"), @ApiImplicitParam(name = "size", value = "条数")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @GetMapping("/list")
    public RespResult<IPage<PayrollVo>> list(@RequestParam(defaultValue = "1") int page,
                                             @RequestParam(defaultValue = "10") int size) {
        return RespResult.success(payrollService.list(page, size));
    }

    @ApiOperation("根据id修改status为0是删除薪资信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "empId", value = "员工id")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @DeleteMapping("/delete")
    public RespResult<Integer> delete(PayrollQo payrollQo) {
        return RespResult.success(payrollService.delete(payrollQo));
    }

    @ApiOperation("根据id修改status为0是批量删除部门信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "deptId", value = "部门id")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @DeleteMapping("/delete/all/{status}")
    public int deleteAll(@RequestBody List<Integer> ids, @PathVariable("status") int status) {
        return payrollService.deleteAll(ids, status);
    }

    @ApiOperation("根据id修改薪资信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "empId", value = "员工id"),
            @ApiImplicitParam(name = "rank", value = "员工等级"),
            @ApiImplicitParam(name = "salary", value = "员工薪资")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @PutMapping("/modify")
    public RespResult<Integer> modify(PayrollQo payrollQo) {
        return RespResult.success(payrollService.modify(payrollQo));
    }


    @ApiOperation("增加薪资信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deptId", value = "部门id"),
            @ApiImplicitParam(name = "empId", value = "员工id"),
            @ApiImplicitParam(name = "rank", value = "员工等级"),
            @ApiImplicitParam(name = "salary", value = "员工薪资")
    })

    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @PostMapping("/add")
    public RespResult<Integer> add(PayrollQo payrollQo) {
        return RespResult.success(payrollService.add(payrollQo));
    }
}
